package com.example.cardview

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.LayoutManager
import com.example.cardview.b.CardConfig

class BCardLayoutManager(val context: Context):LayoutManager() {


    override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State?) {
        detachAndScrapAttachedViews(recycler)
        for (index in 0 until CardConfig.SHOW_MAX_COUNT){
            val itemView = recycler.getViewForPosition(index)
            addView(itemView,0)
            measureChildWithMargins(itemView,0,0)
            val itemW = getDecoratedMeasuredWidth(itemView)
            val itemH = getDecoratedMeasuredHeight(itemView)
            layoutDecorated(itemView, 0, 0, itemW, itemH)



            itemView.translationY=(index*CardConfig.getY(context)).toFloat()


            itemView.scaleX = 1-(index*CardConfig.SCALE).toFloat()

        }



    }

    override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
        return  RecyclerView.LayoutParams(RecyclerView.LayoutParams.WRAP_CONTENT, RecyclerView.LayoutParams.WRAP_CONTENT);
    }


}